/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.dataaccess.hibernate;

import cms.dataaccess.ReviewDeailsDAO;
import cms.exceptions.HibernateAccessLayerException;
import dto.Reviewdetails;
import java.util.List;

/**
 *
 * @author WU DAO BO
 */
public class ReviewDeailsDAOImpl extends AbstractDAO implements ReviewDeailsDAO {

    @Override
    public List<Reviewdetails> getAllReviewDetails() {
        try{
                   
                return this.findAll(Reviewdetails.class);
             } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
             }
    }

    @Override
    public Reviewdetails getReviewDetail(String reviewID) {
             try{
                   
                return (Reviewdetails) this.find(Reviewdetails.class, reviewID);
             } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
             }
    
    }

    @Override
    public List<Reviewdetails> getReviewDetails(String catID) {
                    try{
                   
                return  this.findByCustomizeQuery(Reviewdetails.class, "catID='"+ catID+"'");
             } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
             }
    }

    @Override
    public Reviewdetails getgetReviewDetail(String catID, String contentNo) {
            try{
                   
                return  (Reviewdetails) this.findByCustomizeQuery(Reviewdetails.class, "catID='"+ catID+"'  and contentNo='" + contentNo+ "'").get(0);
                
             } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
             }
    }

    @Override
    public boolean updateReviewDetail(Reviewdetails detail) {
            try{
               if(detail==null) {
                   return false;
               }   
              this.saveOrUpdate(detail);     
              return true;
             } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
             }
    }

    @Override
    public boolean deleteReviewDetail(Reviewdetails detail) {
             try{
               if(detail==null) {
                   return false;
               }   
              this.delete(detail);     
              return true;
             } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
             }
    }

    @Override
    public boolean deleteReviewDetail(String reviewID) {
             try{
               Reviewdetails  detail = this.getReviewDetail(reviewID);
               if(detail==null) {
                   return false;
               }   
              this.delete(detail);     
              return true;
             } catch (Throwable t){
               throw new HibernateAccessLayerException(t.toString());
             }
    }
    
}
